import React from "react";
// Redirect组件用于做重定向
// from和to两个属性，一般情况下需要加exact属性
import { Link, Route, Switch, Redirect } from "react-router-dom";

class Home extends React.Component {
  render() {
    return (
      <>
        <div>home页面</div>
      </>
    );
  }
}

const About = () => {
  return <div>about页面</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v5-路由重定向</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
      </ul>

      <hr />

      <Switch>
        <Redirect from="/" to="/home" exact></Redirect>
        <Route path="/home" component={Home}></Route>
        <Route path="/about" component={About}></Route>
      </Switch>
    </>
  );
};

export default App;
